package treesNgraphs;

import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * Created by Tzachi on 13/10/2014.
 *
 */
public class BfsTree {

    /**
     * iterative
     */
    public static void bfsTree(TreeNode root) {
        Queue<TreeNode> queue = new LinkedBlockingQueue<>();
        queue.add(root);
        while (!queue.isEmpty()) {
            TreeNode node = queue.poll();
            visit(node);
            if (node.getLeftChild() != null) {
                queue.add(node.getLeftChild());
            }
            if (node.getRightChild() != null) {
                queue.add(node.getRightChild());
            }
        }

    }

    public static void visit(TreeNode node) {
        // do something
    }

}
